import {Component, Directive} from '@angular/core';
import { FileUploader } from 'ng2-file-upload';
import { SERVER_API_URL } from '../../app.constants';
import {CollegeMySuffixService} from "./college-my-suffix.service";
import {LocalStorageService, SessionStorageService} from 'ngx-webstorage';

@Component({
    selector: 'jhi-college-my-suffix-import',
    templateUrl: './college-my-suffix-import.component.html'
})
@Directive({
    selector : '[ng2FileSelect]'
})
export class CollegeMySuffixImportComponent {
    public uploader:FileUploader;
    constructor (
        private localStorage: LocalStorageService,
        private sessionStorage: SessionStorageService
    ) {
        const token = this.localStorage.retrieve('authenticationToken') || this.sessionStorage.retrieve('authenticationToken');
        this.uploader= new FileUploader({
            url:SERVER_API_URL+'/api/colleges/import',
            method: "POST",
            itemAlias: "file",
            allowedFileType:["xls","xlsx"],
            headers:[
                {name:"Authorization",value:'Bearer ' + token}
            ]
        });
    }


    public hasBaseDropZoneOver:boolean = false;
    public hasAnotherDropZoneOver:boolean = false;

    private collegeService : CollegeMySuffixService;
    private file : File;

    public fileOverBase(e:any):void {
        this.hasBaseDropZoneOver = e;
    }

    public fileOverAnother(e:any):void {
        this.hasAnotherDropZoneOver = e;
    }

    click(){
        this.collegeService.import(this.file);
    }

}
